package com.dc.service.impl;

import com.dc.base.model.BaseModel;
import com.dc.dao.NoticeDao;
import com.dc.dao.impl.NoticeDaoImpl;
import com.dc.service.NoticeService;

import java.util.List;
import java.util.Map;

public class NoticeServiceImpl implements NoticeService {

    NoticeDao noticeDao = new NoticeDaoImpl();
    @Override
    public BaseModel addNotice(Object[] params) throws Exception {
        BaseModel baseModel = new BaseModel();
        String sql ="insert into t_notice(notice_title,notice_content,time) values(?,?,?)";

        int result = noticeDao.addNotice(sql,params);

        if(result>0){
            baseModel.setCode(1);
            baseModel.setMessage("添加成功");
        }else {
            baseModel.setCode(0);
            baseModel.setMessage("添加失败");
        }
        return baseModel;
    }

    @Override
    public BaseModel updateNotice(Object[] params) throws Exception {
        return null;
    }

    @Override
    public BaseModel deleteNotice(int id) throws Exception {
        BaseModel baseModel = new BaseModel();
        System.out.println(id);
        String sql = "delete from t_notice where notice_id = "+id+"";
        int result = noticeDao.deleteNotice(sql);
        if(result>0){
            baseModel.setCode(1);
            baseModel.setMessage("删除成功");
        }else {
            baseModel.setCode(0);
            baseModel.setMessage("删除失败");
        }
        return baseModel;
    }

    @Override
    public BaseModel selectNotice(Object[] params) throws Exception {
        BaseModel baseModel=new BaseModel();
        String sql="select * from t_notice";
        List lists=noticeDao.selectNotice(sql,null);
        baseModel.setCode(1);
        baseModel.setMessage("查询成功");
        baseModel.setData(lists);
        return baseModel;
    }
}
